﻿using Melee.Contract;
using StructureMap;

namespace Melee.Controller.Handlers
{
    public class HandlerFactory : IHandlerFactory
    {
        public RequestHandler GetHandlers()
        {
            RequestHandler handlers = CreateLoginHandler();

            handlers.SetNextHandler(new CheckLoginHandler())
                .SetNextHandler(CreateSignOutHandler())
                .SetNextHandler(CreateGetMessageHandler())
                .SetNextHandler(CreateSendMessageHandler())
                .SetNextHandler(CreateGetCityDetailHandler())
                .SetNextHandler(CreateGetInitializationDataHandler())
                .SetNextHandler(new InvalidHandler());
            return handlers;
        }

        private LoginHandler CreateLoginHandler()
        {
            return new LoginHandler(ObjectFactory.GetInstance<IUserService>());
        }

        private SignOutHandler CreateSignOutHandler()
        {
            return new SignOutHandler();
        }

        private ListenHandler CreateGetMessageHandler()
        {
            return new ListenHandler();
        }

        private SendMessageHandler CreateSendMessageHandler()
        {
            return new SendMessageHandler();
        }

        private GetCityDetailHandler CreateGetCityDetailHandler()
        {
            return new GetCityDetailHandler(ObjectFactory.GetInstance<ICityService>());
        }

        private GetInitializationDataHandler CreateGetInitializationDataHandler()
        {
            return new GetInitializationDataHandler(ObjectFactory.GetInstance<IGameService>());
        }
    }
}
